package com.lvy.hczn.front.business.controller;

import java.util.List;

import com.lvy.hczn.front.system.domain.business.DataException;
import com.lvy.hczn.front.system.service.DataExceptionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.lvy.hczn.front.common.annotation.Log;
import com.lvy.hczn.front.common.enums.BusinessType;
import com.lvy.hczn.front.common.core.controller.BaseController;
import com.lvy.hczn.front.common.core.domain.AjaxResult;
import com.lvy.hczn.front.common.utils.poi.ExcelUtil;
import com.lvy.hczn.front.common.core.page.TableDataInfo;

/**
 * Controller
 *
 * @author ruoyi
 * @date 2023-07-04
 */
@Controller
@RequestMapping("/system/exception")
public class DataExceptionController extends BaseController {
    private String prefix = "system/exception";

    @Autowired
    private DataExceptionService dataExceptionService;

    @RequiresPermissions("system:exception:view")
    @GetMapping()
    public String exception() {
        return prefix + "/list";
    }

    /**
     * 查询列表
     */
    @RequiresPermissions("system:exception:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DataException dataException) {
        startPage();
        List<DataException> list = dataExceptionService.selectDataExceptionList(dataException);
        return getDataTable(list);
    }

    /**
     * 导出列表
     */
    @RequiresPermissions("system:exception:export")
    @Log(title = "", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DataException dataException) {
        List<DataException> list = dataExceptionService.selectDataExceptionList(dataException);
        ExcelUtil<DataException> util = new ExcelUtil<DataException>(DataException.class);
        return util.exportExcel(list, "数据");
    }

    /**
     * 新增
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存
     */
    @RequiresPermissions("system:exception:add")
    @Log(title = "", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DataException dataException) {
        return toAjax(dataExceptionService.insertDataException(dataException));
    }

    /**
     * 修改
     */
    @RequiresPermissions("system:exception:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        DataException dataException = dataExceptionService.selectDataExceptionById(id);
        mmap.put("dataException", dataException);
        return prefix + "/edit";
    }

    /**
     * 修改保存
     */
    @RequiresPermissions("system:exception:edit")
    @Log(title = "", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DataException dataException) {
        return toAjax(dataExceptionService.updateDataException(dataException));
    }

    /**
     * 删除
     */
    @RequiresPermissions("system:exception:remove")
    @Log(title = "", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(dataExceptionService.deleteDataExceptionByIds(ids));
    }
}